﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsTextItem>
#include <QGraphicsRectItem>
#include <QGraphicsPixmapItem>
#include <QDebug>
#include "MyGrid.h"
#include <QTimerEvent>
#include <QMessageBox>
#include <QKeyEvent>
#include "mystudio.h"
#include <QTime>

namespace Ui {
class MainWindow;
}




class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    void initUi();

private:
    Ui::MainWindow *ui;
    QGraphicsScene* scene;
    QGraphicsView* view;
    QRect mRect;
    //地图矩阵
    QVector<QVector<MyGrid*>> gridTab;
    //蛇的位置,方向,设置蛇的位置
    QList<QPoint> snakePoi;
    int snakeDir = 0;   //上1下2左3右4不动0
    int snakeNextDir = 0;//0表示原方向不动
    void addSnack(int x,int y);
    void moveSnake();

    //添加奖励
    QList<QPoint> award;
    void addAward();

    //定时器
    int timerId;
    bool start = 0;

protected:
    void timerEvent(QTimerEvent* event) override;
    void keyPressEvent(QKeyEvent *event) override;
private slots:
    void on_actionStart_triggered();
    void on_actionStop_triggered();
};

#endif // MAINWINDOW_H
